/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Check_Report_Work",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using ATkg.BizAppProject.DomainModels;
using ATkg.BizAppProject.IServices;
using Microsoft.AspNetCore.Authorization;

namespace ATkg.BizAppProject.Controllers
{
    public partial class Check_Report_WorkController
    {
        private readonly ICheck_Report_WorkService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public Check_Report_WorkController(
            ICheck_Report_WorkService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        public class ActionModel
        {
            public string Action { get; set; }
            public string ProductCode { get; set; }
            public string EquipmentNo { get; set; }
            public string InspectionId { get; set; }
            public string PlatingId { get; set; }
            public string Username { get; set; }
            public int Quantity { get; set; }
            public DateTime CurrentTime { get; set; }
        }

        // 将网页中填写的审核信息传入数据库
        [HttpPost("GetInfoFromWeb")]
        [AllowAnonymous]
        public async Task<JsonResult> GetInfoFromWeb([FromBody] ActionModel model)
        {
            try
            {

                var r = await Service.DealDataFromWeb(model);
                return new JsonResult(new
                {
                    Success = true,
                    Message = "提交成功！",
                    Data = r  // 新增：返回string格式的时间
                });

            }
            catch (Exception ex)
            {
                // 返回错误的 JsonResult
                return new JsonResult(new { Success = false, Message = $"处理失败: {ex.Message}" })
                {
                    StatusCode = 500 // 设置 HTTP 状态码
                };
            }


        }
    }
}
